<?php
use yii\helpers\Url;

$web = Url::base();

$site_name = \app\models\Mall::getCurrentInstitutionSiteName();
$this->title = $site_name . '-积分转赠';
?>

<link rel="stylesheet" type="text/css" href="<?= $web ?>/css/mall-m/integral-transfer.css"/>
<script type="text/javascript" src="<?= $web ?>/js/tools.js"></script>
<script type="application/javascript">
    //确认
    function onConfirm() {
        var user_integral = <?= $integral ?>;
        var number = $("#number").val();
        var integral = $("#integral").val();
        var data = {};
        data.number = number;
        data.integral = integral;

        if (number == null || number == '') {
            alert("请输入对方手机号");
            return;
        }
        if (!checkMobile(number)) {
            alert("输入的手机号有误，请重新输入");
            return;
        }
        if (integral == null || integral == '') {
            alert("请输入转赠积分");
            return;
        }
        if (parseInt(integral) > parseInt(user_integral)) {
            alert("转赠积分不能大于账户余额");
            return;
        }

        if (confirm("确定转赠吗？")) {
            requestJson("integral-transfer-handler", data, true, function (response) {
                if (response.status == 0) {
                    alert('操作成功！');
                    var href = decodeURIComponent(window.location.href);
                    window.location.href = href;
                } else {
                    alert('操作失败！' + response.message);
                }
            });
        }
    }
</script>
<div class="main">
    <div class=" balance">
        <p>积分账户余额：<span><?= floor($integral) ?></span></p>
    </div>
    <div class="phone-num">
        <p>对方手机号</p>
        <input id="number" type="tel" class="number" type="text" value=""/>
    </div>
    <div class="prsesent-integral">
        <p>转赠积分</p>
        <input id="integral" type="number" value="" onkeyup="checkNumVal_int(this)"/>
    </div>
    <a href="javascript:void(0)">
        <div class="affirm-btn" onclick="onConfirm()">确认</div>
    </a>
</div>
